#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
int GetMonthDay(int year, int month)
{
	static int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };

	if (month == 2 && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)) {
		return 29;
	}
	return arr[month];
}

int main()
{
	int m = 0;
	scanf("%d", &m);
	while (m > 0)
	{
		int year = 0;
		int month = 0;
		int day = 0;
		int add_day = 0;
	
		cin >> year >> month >> day >> add_day;
		day += add_day;

		while (day > GetMonthDay(year, month))
		{
			day -= GetMonthDay(year, month);
			month++;
			if (month == 13) {
				month = 1;
				year++;
			}
		}
		cout << year << "-" << month << "-" << day << endl;
		m--;
	}


	return 0;
}



